<%--
  Created by IntelliJ IDEA.
  User: cxy
  Date: 2018-06-13
  Time: 10:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/bootstrap/css/bootstrap.css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/table/bootstrap-table.min.css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/date/bootstrap-datetimepicker.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/hplus/css/plugins/sweetalert/sweetalert.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/table/bootstrap-table.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/date/Moment.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/date/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/hplus/js/plugins/sweetalert/sweetalert.min.js"></script>
</head>

<body>
<div class="panel panel-default">
    <div class="panel-body">
        <form class="form-inline">
            <button  type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal" id="add1">添加</button>

        </form>
    </div>
</div>
<table id="table"></table>
<div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">添加药品</h4>
            </div>
            <div class="modal-body">
                <form>
                    <input  type="hidden" id="goodsid" name="id" />
                    <div class="form-group">
                        <label for="Medicineid">药品编号：</label>
                        <input type="text" class="form-control" id="Medicineid">
                    </div>
                    <div class="form-group">
                        <label for="MName">药品名称：</label>
                        <input type="text" class="form-control" id="MName">

                    </div>
                    <div class="form-group">
                        <label for="MPrice">药品单价：</label>
                        <input type="text" class="form-control" id="MPrice"/>
                    </div>
                    <div class="form-group">
                        <label for="spec">药品规格：</label>
                        <input type="text" class="form-control" id="Spec"/>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="Dosageform">药品剂型：</label>
                        <input type="text" class="form-control" id="Dosageform"/>

                        </select>
                    </div>

                    <div class="form-group">
                        <label for="MNbumber">药品数量：</label>
                        <input type="text" class="form-control" id="MNbumber"/>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="StockChange">0 入库 1 出库：</label>
                        <input type="text" class="form-control" id="StockChange"/>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="Applicant">申请人：</label>
                        <input type="text" class="form-control" id="Applicant"/>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="StockChangeDate">变动时间：</label>
                        <input type="text" class="form-control" id="StockChangeDate"/>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="ChangeNumber">变动数量：</label>
                        <input type="text" class="form-control" id="ChangeNumber"/>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="SurplusNumber">剩余数量：</label>
                        <input type="text" class="form-control" id="SurplusNumber"/>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="TotalAmount">总金额：</label>
                        <input type="text" class="form-control" id="TotalAmount"/>
                        </select>
                    </div>


                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">关闭</button>
                <button onclick="add()" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">

    $("#add1").bind("click",function () {

        $("#add").modal("show");

    })


    $(function () {

        $("#table").bootstrapTable({
            url:'${pageContext.request.contextPath}/goods/queryPage',
            columns: [
                {
                    checkbox:true
                },{
                    field: 'medicineid',
                    title: '药品编号'
                }, {
                    field: 'mName',
                    title: '药品名称'
                }, {
                    field: 'mPrice',
                    title: '药品单价'
                },  {
                    field: 'spec',
                    title: '药品规格'
                },  {
                    field: 'dosageform',
                    title: '药品剂型'
                },  {
                    field: 'termofvalidity',
                    title: '药品有效期'
                },  {
                    field: 'mNbumber',
                    title: '药品数量'
                },  {
                    field: 'stockChange',
                    title: '0 入库 1 出库'
                },  {
                    field: 'applicant',
                    title: '申请人'
                },  {
                    field: 'stockChangeDate',
                    title: '变动时间'
                },  {
                    field: 'changeNumber',
                    title: '变动数量'
                },  {
                    field: 'surplusNumber',
                    title: '剩余数量'
                },  {
                    field: 'totalAmount',
                    title: '总金额'
                }
            ],
            clickToSelect:true,
            singleSelect:true,
            height:380,
//查询参数
            queryParamsType:'',

//在底部显示分页条
            pagination:true,
//启服务器端分页
            sidePagination:'server',
            pageNumber:1,
            pageSize:5,
            pageList:[5,10,15],
            queryParams:function(params){
                var temp = {
                    'pageNumber': params.pageNumber,
                    'pageSize': params.pageSize,
                    'nName':$("#MName").val()
                } ;
                return temp ;
            }
        }) ;



    });

    function add() {
        var medicineid = $("#Medicineid").val();
        var mName = $("#MName").val();
        var mPrice = $("#MPrice").val();
        var spec = $("#Spec").val();
        var dosageform = $("#Dosageform").val();
        var termofvalidity = $("#Termofvalidity").val();
        var mNbumber = $("#MNbumber").val();
        var stockChange = $("#StockChange").val();
        var applicant = $("#Applicant").val();
        var stockChangeDate = $("#StockChangeDate").val();
        var changeNumber = $("#ChangeNumber").val();
        var surplusNumber = $("#SurplusNumber").val();
        var totalAmount = $("#TotalAmount").val();
        var data =JSON.stringify({
            "medicineid":medicineid,"mName": mName, "mPrice": mPrice, "spec": spec, "dosageform": dosageform,"termofvalidity":termofvalidity,"mNbumber":mNbumber,"stockChange":stockChange,"applicant":applicant,"stockChangeDate":stockChangeDate,"changeNumber":changeNumber,"surplusNumber":surplusNumber,"totalAmount":totalAmount
        })

        //send ajax
        $.ajax({
            url: "${pageContext.request.contextPath}/goods/add",
            data: data,
            type: "post",
            ContentType:"application/json",
            dataType: "text",
            success: function (data) {
                alert("添加成功");

                //绑定到table上
                $("#table").bootstrapTable("refresh",data);

                //关闭对话框
                $('#add').modal('hide');
            },
            error:function () {
                alert("添加失败");
            }
        })
    }

</script>
</html>
